package com.asset.action;

import com.asset.pojo.Department;
import com.asset.pojo.User;
import org.springframework.web.bind.support.SessionStatus;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

/**
 * Created by gongshaobo on 2017/1/13  10:55.
 */
public class LoginAction extends BaseAction {
    private User user;
    private String name;
    private String password;
    private User userTemp;
    public String toLogin(){

//        String company = "";
//        company = company.replaceAll("\\n",",");
//        String [] paces= company.split(",");
//        boolean flag = true;
//        List<String> city = new ArrayList<String>();
//        for ( int i = 0 ; i < paces.length; i ++ ) {
//            int testLenght = 0;
//            for(String s:city){
//                if(paces[i].equals(s)){
//                    break;
//                }else{
//                    testLenght++;
//                }
//            }
//            if(testLenght == city.size()){
//                city.add(paces[i]);
//            }
//        }
//        for(String s : city){
//            Department department = new Department();
//            department.setName(s);
//            departService.addDepart(department);
//        }
//        System.out.print(city);
        return SUCCESS;
    }
    public String login(){
        User loginSuccUser = userService.getUserByLoginInfo(user.getName(),user.getPassword());
        if(loginSuccUser != null){
            getSession().setAttribute(UserKEY,loginSuccUser);
            return SUCCESS;
        }else{
            name=user.getName();
            password=user.getPassword();
            return NONE;
        }
    }
    public String logout(){
        if(session != null){
            session.removeAttribute(UserKEY);
        }
        return SUCCESS;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public User getUserTemp() {
        return userTemp;
    }

    public void setUserTemp(User userTemp) {
        this.userTemp = userTemp;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}
